﻿using AutoMapper;
using Core.Dtos;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Core.Mappers
{
    public class CacheProfile : Profile
    {
        protected override void Configure()
        {
            Mapper.CreateMap<KeyValuePair<string, object>, CacheEntryDto>()
                    .ForMember(dest => dest.Id, opts => opts.MapFrom(src => src.Key))
                    .ForMember(dest => dest.Value, opts => opts.MapFrom(src => FormatValue(src.Value)));
            Mapper.AddProfile<ListResponseProfile<KeyValuePair<string, object>, CacheEntryDto>>();
        }

        private string FormatValue(object value)
        {
            IList list = value as IList;
            if (list != null)
                return string.Format("List : {0}", list.Count);
            else
                return value.ToString();
        }
    }
}
